package com.cake.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cake.param.ThermodynamicParam;
import com.cake.service.inter.IThermodynamicService;

/**
 * 热力图控制层
 * @author Administrator
 *
 */
@RestController
@RequestMapping(value = "thermodynamic")
public class ThermodynamicChartController {

	@Autowired
	private IThermodynamicService thermodynamicService;
	
	/**
	 * 收货人数量热力图
	 * @param thermodynamicParam
	 * @return
	 */
	@PostMapping(value = "thermodynamicChartForReceiverTotal")
	public Object thermodynamicChartForReceiverTotal(@RequestBody ThermodynamicParam thermodynamicParam){
		return thermodynamicService.selectReceiverTotalByDistrictOrCityOrProvince(handleThermodynamicParam(thermodynamicParam));
	}
	
	/**
	 * 订单数量热力图
	 * @return
	 */
	@PostMapping(value = "thermodynamicChartForOrderTotal")
	public Object thermodynamicChartForOrderTotal(@RequestBody ThermodynamicParam thermodynamicParam){
		if (thermodynamicParam.getAreaType().equals(2)) {
			thermodynamicParam.setAreaCode(51);
		}else if(thermodynamicParam.getAreaType().equals(3)){
			thermodynamicParam.setAreaCode(5101);
		}
		/**
		 * 对于前台控制符的处理
		 */
		thermodynamicParam.setStartTime(StringUtils.isEmpty(thermodynamicParam.getStartTime()) ? null : thermodynamicParam.getStartTime());
		thermodynamicParam.setEndTime(StringUtils.isEmpty(thermodynamicParam.getEndTime()) ? null : thermodynamicParam.getEndTime());
		return thermodynamicService.selectOrderTotalByDistrictOrCityOrProvince(handleThermodynamicParam(thermodynamicParam));
	}
	
	/**
	 * 销售金额热力图
	 * @return
	 */
	@PostMapping(value = "thermodynamicChartForAmountTotal")
	public Object thermodynamicChartForAmountTotal(@RequestBody ThermodynamicParam thermodynamicParam){
		if (thermodynamicParam.getAreaType().equals(2)) {
			thermodynamicParam.setAreaCode(51);
		}else if(thermodynamicParam.getAreaType().equals(3)){
			thermodynamicParam.setAreaCode(5101);
		}
		/**
		 * 对于前台控制符的处理
		 */
		thermodynamicParam.setStartTime(StringUtils.isEmpty(thermodynamicParam.getStartTime()) ? null : thermodynamicParam.getStartTime());
		thermodynamicParam.setEndTime(StringUtils.isEmpty(thermodynamicParam.getEndTime()) ? null : thermodynamicParam.getEndTime());
		return thermodynamicService.selectAmountByDistrictOrCityOrProvince(handleThermodynamicParam(thermodynamicParam));
	}
	
	/**
	 * 对前端传来的热力图参数对象做处理
	 * @param thermodynamicParam
	 * @return
	 */
	private ThermodynamicParam handleThermodynamicParam(ThermodynamicParam thermodynamicParam){
		if (thermodynamicParam.getAreaType().equals(2)) {
			thermodynamicParam.setAreaCode(51);
		}else if(thermodynamicParam.getAreaType().equals(3)){
			thermodynamicParam.setAreaCode(5101);
		}
		return thermodynamicParam;
	}
}
